<template>
<uni-shadow-root class="partials-task_list-index"><block v-if="(!receiveData.androidTemplate||receiveData.androidTemplate=='typeOne')">
  <view class="container">
      <view class="task_list" v-if="taskList&&taskList.length!=0" style="height: receiveData.androidTemplate=='typeOne'?'0':'80rpx'">
          <view v-for="(item,index) in (taskList)" class="task_item" :data-link="'task_detail.html?taskId='+(item.id)" @click="tolinkUrl" v-if="limitState!=0?index<receiveData.jsonData.count:'ture'">
              <view class="task_item_top">
                  <text class="task_type_tag" :style="'background:'+(defaultColor)" v-if="item.topOrder>0">顶</text>
                  <text class="task_type_tag" :style="'background:'+(defaultColor)" v-if="item.taskMode==1">抢单</text>
                  <text class="task_type_tag" :style="'background:'+(defaultColor)" v-if="item.taskMode==2">预选</text>
                  <text class="task_item_price" :style="'color:'+(defaultColor)" v-if="item.priceMode==0">免费</text>
                  <text class="task_item_price" :style="'color:'+(defaultColor)" v-if="item.priceMode==1">可议价</text>
                  <text class="task_item_price" :style="'color:'+(defaultColor)" v-if="item.priceMode==2">￥{{item.taskPrice}}</text>
                  <text class="task_item_name">{{item.name}}</text>
                  <image class="hb_block" v-if="item.tipPrice" src="https://image1.sansancloud.com/xianhua/2020_5/8/10/20/37_663.jpg?x-oss-process=style/preview_120"></image>
              </view>
              <view class="task_item_content">
                  {{item.content}}
              </view>
              <scroll-view class="tags_content" scroll-x v-if="item.tags">
                <text v-for="(item,index) in (item.managerTagArray)" class="tags_item" :style="'background:'+(defaultColor)+'22;color:'+(defaultColor)">{{item}}</text>
                <text v-for="(item,index) in (item.tagArray)" class="tags_item" style="border: 1rpx solid #eee;">{{item}}</text>
              </scroll-view>
              <view class="task_item_bottom">
                  <view class="task_item_attend_count">终选<text :style="'color:'+(defaultColor)+';margin:0 4rpx'">{{item.taskServantCount||0}}</text>人</view>
                  <view class="task_item_state">
                      <text class="task_item_state_text" v-if="item.taskStatus==0">未发布</text>
                      <text class="task_item_state_text" v-if="item.taskStatus==1">待审核</text>
                      <text class="task_item_state_text" v-if="item.taskStatus==2">审核拒绝</text>
                      <text class="task_item_state_text" v-if="item.taskStatus==3">{{item.taskEndTime||'不限期'}}截止</text>
                      <text class="task_item_state_text" v-if="item.taskStatus==4">任务进行中</text>
                      <text class="task_item_state_text" v-if="item.taskStatus==5">待验收</text>
                      <text class="task_item_state_text" v-if="item.taskStatus==6">已完成</text>
                  </view>
              </view>
          </view>
      </view>
      <view class="noproduct" v-else style="margin-top: receiveData.androidTemplate=='typeOne'?'100rpx':'200rpx'">
        <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
        <text>没有相关任务</text>
      </view>
  </view>
</block>
<block v-if="receiveData.androidTemplate == 'typeTwo'">
  
</block></uni-shadow-root>
</template>

<script>

global['__wxRoute'] = 'partials/task_list/index'
const app = getApp();
Component({
  properties: {
    receiveData: {
      type: Object,
      value: 'default value',
    },
  },
  data: {
    setting: null, 
    taskList: null,
    limitState:0,
    params:null,
    listPage: {
      page: 1,
      pageSize: 0,
      totalSize: 0,
      curpage: 1,
      taskTypeId:0,
    },
  },
  ready: function () {
    let that = this;
    console.log("====taskList-data=====", that.data.receiveData);
    that.initSetting();
    if (that.data.receiveData.jsonData ) {
        that.data.params=Object.assign({},that.data.params,that.data.receiveData.jsonData)
        that.getData(that.data.params)
        if(that.data.receiveData.jsonData.count){
            that.setData({ limitState: that.data.receiveData.jsonData.count })
        }
    }else{
        that.data.listPage=Object.assign({},that.data.listPage,that.data.receiveData)
        that.getData(that.data.listPage)
    }
    console.log("====taskList-limitState=====", that.data.limitState)
    console.log("====taskList-params=====", that.data.params)
  },
  methods: {
    setDataFun:function(data){
        let that=this;
        console.log("setDataFun",data)
        that.setData({params: data})
        that.getData(data)
    },
    /* 获取数据 */
    getData: function (param) {
      var that = this
      let params=Object.assign({},param,{
          taskStatus:-1
      })
      that.setData({listPage:param})
      console.log("===params==",params)
      var customIndex = app.globalData.AddClientUrl("/wx_find_tasks.html", params)
      app.globalData.showToastLoading('loading', true)
      wx.request({
        url: customIndex.url,
        header: app.globalData.header,
        success: function (res) {
          wx.hideLoading()
          console.log(res.data)
          let data=res.data.relateObj.result
          that.data.listPage.pageSize = res.data.relateObj.pageSize
          that.data.listPage.page = res.data.relateObj.curPage
          that.data.listPage.totalSize = res.data.relateObj.totalSize
          let dataArr = that.data.taskList;
          let tagArray=[];
          for (let i = 0; i < data.length; i++) {
            if (data[i].tags && data[i].tags != '') {
              tagArray = JSON.parse(data[i].tags)
              data[i].tagArray = tagArray;
            }
            if (data[i].managerTags && data[i].managerTags != '') {
              tagArray = JSON.parse(data[i].managerTags)
              if(data[i].payedPrice>0){
                  tagArray.splice(tagArray.length,1,'已交定金')
              }
              data[i].managerTagArray = tagArray;
            }
          }
          console.log("===data====",data)
          if (param.page == 1) {
            dataArr = []
          }
          if (!data || data.length == 0) {
            that.setData({ taskList: [] })
          } else {
            if (dataArr == null) { dataArr = [] }
            dataArr = dataArr.concat(data)
            that.setData({ taskList: dataArr })
          }
          wx.hideLoading()
        },
        fail: function (res) {
          console.log("fail")
          wx.hideLoading()
          app.globalData.loadFail()
        }
      })
    },
    calling: function (e) {
      console.log('====e===', e)
      let phoneNumber = e.currentTarget.dataset.phonenumber
      wx.makePhoneCall({
        phoneNumber: phoneNumber, //此号码并非真实电话号码，仅用于测试
        success: function () {
          console.log("拨打电话成功！")
        },
        fail: function () {
          console.log("拨打电话失败！")
        }
      })
    },
    toIndex() {
      app.globalData.toIndex()
    },
    tolinkUrl: function (e) {
      let linkUrl = e.currentTarget.dataset.link
      app.globalData.linkEvent(linkUrl)
    },
    initSetting() {
      this.setData({ 
        setting: app.globalData.setting ,
        defaultColor:app.globalData.setting.platformSetting.defaultColor,
        secondColor:app.globalData.setting.platformSetting.secondColor,
       })
    },
    pullDownRefreshFun: function () {
      this.data.listPage.page = 1
      this.getData(this.data.listPage)

    },
    reachBottomFun: function () {
      var that = this;
      console.log("that.data.listPage",that.data.listPage)
      if (that.data.listPage.totalSize > that.data.listPage.curPage * that.data.listPage.pageSize) {
        that.data.listPage.page++
        that.getData(this.data.listPage);
      }else{
          console.log("到底了")
          wx.showToast({
            title: "到底了~",
            image: '/wxcomponents/images/icons/tip.png',
            duration: 1000
          });
      }
    },
  }
})
export default global['__wxComponents']['partials/task_list/index']
</script>
<style platform="mp-weixin">
@import 'type_one/index.css';
</style>